#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import math
from scipy.stats import skew
from matplotlib.lines import Line2D


# In[2]:


df = pd.read_csv("D:/research/recordbreak/rb_ratio10.csv")
print(df)


# In[3]:


# Extracting data for each river
indus_data = df[['indus70','indus10', 'indus50', 'indus90']]
kabul_data = df[['kabul70','kabul10', 'kabul50', 'kabul90']]
jehlum_data = df[['jehlum70','jehlum10', 'jehlum50', 'jehlum90']]
chenab_data= df[['chenab70','chenab10', 'chenab50', 'chenab90']]

# Calculate mean, min, and max values for each river and each RCP
def calculate_values(data):
    rcp_45_values = data[df['var'].str.contains('ratio45')]
    rcp_85_values = data[df['var'].str.contains('ratio85')]

    mean_values_45 = rcp_45_values.mean()
    min_values_45 = rcp_45_values.min()
    max_values_45 = rcp_45_values.max()

    mean_values_85 = rcp_85_values.mean()
    min_values_85 = rcp_85_values.min()
    max_values_85 = rcp_85_values.max()

    return (mean_values_45, min_values_45, max_values_45), (mean_values_85, min_values_85, max_values_85)

# Calculate values for each river
indus_values = calculate_values(indus_data)
kabul_values = calculate_values(kabul_data)
jehlum_values = calculate_values(jehlum_data)
chenab_values = calculate_values(chenab_data)


# Plotting all rivers in one graph
fig, ax = plt.subplots(figsize=(18, 9)) 
x_offset=0.3
# Plotting Indus River
ax.errorbar(['indus70','indus10', 'indus50', 'indus90'], indus_values[0][0], 
            yerr=[indus_values[0][0] - indus_values[0][1], indus_values[0][2] - indus_values[0][0]],
            fmt='d', label='Indus - RCP 4.5', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['indus70','indus10', 'indus50', 'indus90'], indus_values[1][0], 
            yerr=[indus_values[1][0] - indus_values[1][1], indus_values[1][2] - indus_values[1][0]],
            fmt='o', label='Kabul - RCP 8.5', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Kabul River
ax.errorbar(['kabul70','kabul10', 'kabul50', 'kabul90'], kabul_values[0][0], 
            yerr=[kabul_values[0][0] - kabul_values[0][1], kabul_values[0][2] - kabul_values[0][0]],
            fmt='d', label='Kabul - RCP 4.5', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['kabul70','kabul10', 'kabul50', 'kabul90'], kabul_values[1][0], 
            yerr=[kabul_values[1][0] - kabul_values[1][1], kabul_values[1][2] - kabul_values[1][0]],
            fmt='o', label='Kabul - RCP 8.5', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Jehlum River
ax.errorbar(['jehlum70','jehlum10', 'jehlum50', 'jehlum90'], jehlum_values[0][0], 
            yerr=[jehlum_values[0][0] - jehlum_values[0][1], jehlum_values[0][2] - jehlum_values[0][0]],
            fmt='d', label='Jehlum - RCP 4.5', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['jehlum70','jehlum10', 'jehlum50', 'jehlum90'], jehlum_values[1][0], 
            yerr=[jehlum_values[1][0] - jehlum_values[1][1], jehlum_values[1][2] - jehlum_values[1][0]],
            fmt='o', label='Jehlum - RCP 8.5', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)

# Plotting Chenab River
ax.errorbar(['chenab70','chenab10', 'chenab50', 'chenab90'], chenab_values[0][0], 
            yerr=[chenab_values[0][0] - chenab_values[0][1], chenab_values[0][2] - chenab_values[0][0]],
            fmt='d', label='Chenab - RCP 4.5', color='teal', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)
ax.errorbar(['chenab70','chenab10', 'chenab50', 'chenab90'], chenab_values[1][0], 
            yerr=[chenab_values[1][0] - chenab_values[1][1], chenab_values[1][2] - chenab_values[1][0]],
            fmt='o', label='Chenab - RCP 8.5', color='red', alpha=0.8, linewidth=4, markersize=16,elinewidth=4)


# Adding vertical lines between rivers
ax.axvline(x=3.5, color='gray', linestyle='--', linewidth=2)  # Between Indus and Jehlum
ax.axvline(x=7.5, color='gray', linestyle='--', linewidth=2)  # Between Jehlum and Chenab
ax.axvline(x=11.5, color='gray', linestyle='--', linewidth=2)  # Between Chenab and Kabul

#ax.set_xlabel('Years (2023, 2050, 2098)')  # Adjust the x-axis label
ax.set_ylabel('Probability Ratio', fontsize=20, fontweight='bold')
#ax.set_title('Error Bar Plot for River Scenarios')
handles, labels = ax.get_legend_handles_labels()
# Selecting and adjusting the legend entries for RCP 4.5 and RCP 8.5
ax.legend([handles[0], handles[3]], ['RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 20, 'weight': 'bold'})  # Manually setting legend labels

years = ['1','2', '3', '4'] * 4  # Years repeated for the number of river groups
ax.set_xticks(range(len(years)))  # Setting positions for the ticks
ax.set_xticklabels(years, rotation=0, fontsize=16, weight='bold')  # Setting custom labels for the primary x-axis

#river_names = [None, 'Indus', None, None, 'Jehlum', None, None, 'Chenab',None,  'Kabul' ]  # River names repeated for the number of years
#river_positions = [1.5, 4.75, 7.5, 11.75]  # Midpoints between each pair of years for centering the river names
#ax2 = ax.twiny()
#ax2.set_xticks(river_positions)  # Setting positions for the ticks based on river names' midpoints
#ax2.set_xticklabels([name for name in river_names if name is not None])  # Setting custom labels for the secondary x-axis (top)
#ax2.xaxis.tick_top()  # Placing the secondary x-axis at the top
ax.tick_params(axis='x', labelsize=22, width=4, length=12)
ax.tick_params(axis='y', labelsize=22, width=4, length=12)
ax.set_ylim(-2, 4)
ax.tick_params(axis='y', labelsize=22)
for label in ax.yaxis.get_ticklabels():
    label.set_fontweight('bold')
plt.tight_layout()
#boundry thickness
ax = plt.gca()
for spine in ax.spines.values():
    spine.set_linewidth(4)
ax.yaxis.grid(True, linestyle='--', linewidth=1) 
plt.show()


# In[4]:


fig, ax = plt.subplots(figsize=(20, 10)) 
x_offset = 0.3

# Plotting Indus River
ax.errorbar(['indus70', 'indus10', 'indus50', 'indus90'], indus_values[0][0], 
            yerr=[indus_values[0][0] - indus_values[0][1], indus_values[0][2] - indus_values[0][0]],
            fmt='d', label='Indus - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
ind_values = np.arange(len(['indus70', 'indus10', 'indus50', 'indus90']))
shifted_ind = ind_values + x_offset
shift_ind = ind_values -0.3
ax.errorbar(shifted_ind, indus_values[1][0], 
            yerr=[indus_values[1][0] - indus_values[1][1], indus_values[1][2] - indus_values[1][0]],
            fmt='o', label='Indus - RCP 8.5', color='red', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)
ind_obs = (1.5, 1.25,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_ind, ind_obs, marker='s',  color='black', s=400)

# Plotting Kabul River
ax.errorbar(['kabul70', 'kabul10', 'kabul50', 'kabul90'], kabul_values[0][0], 
            yerr=[kabul_values[0][0] - kabul_values[0][1], kabul_values[0][2] - kabul_values[0][0]],
            fmt='d', label='Kabul - RCP 4.5', color='teal', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)
kab_values = np.arange(len(['kabul70', 'kabul10', 'kabul50', 'kabul90']))
shifted_kab = kab_values + 4.2
shift_kab = kab_values + 3.7
ax.errorbar(shifted_kab, kabul_values[1][0], 
            yerr=[kabul_values[1][0] - kabul_values[1][1], kabul_values[1][2] - kabul_values[1][0]],
            fmt='o', label='Kabul - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
kab_obs = (2.5, 1.75,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_kab, kab_obs, marker='s',  color='black', s=400)

# Plotting Jehlum River
ax.errorbar(['jehlum70', 'jehlum10', 'jehlum50', 'jehlum90'], jehlum_values[0][0], 
            yerr=[jehlum_values[0][0] - jehlum_values[0][1], jehlum_values[0][2] - jehlum_values[0][0]],
            fmt='d', label='Jehlum - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

jeh_values = np.arange(len(['jehlum70', 'jehlum10', 'jehlum50', 'jehlum90']))
shifted_jeh = jeh_values + 8.3
shift_jeh = jeh_values + 7.7
ax.errorbar(shifted_jeh, jehlum_values[1][0], 
            yerr=[jehlum_values[1][0] - jehlum_values[1][1], jehlum_values[1][2] - jehlum_values[1][0]],
            fmt='o', label='Jehlum - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
jeh_obs = (0.9, 0.825,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_jeh, jeh_obs, marker='s',  color='black', s=400)
# Plotting Chenab River
ax.errorbar(['chenab70', 'chenab10', 'chenab50', 'chenab90'], chenab_values[0][0], 
            yerr=[chenab_values[0][0] - chenab_values[0][1], chenab_values[0][2] - chenab_values[0][0]],
            fmt='d', label='Chenab - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

che_values = np.arange(len(['chenab70', 'chenab10', 'chenab50', 'chenab90']))
shifted_che = che_values + 12.3
shift_che = che_values + 11.7
ax.errorbar(shifted_che, chenab_values[1][0], 
            yerr=[chenab_values[1][0] - chenab_values[1][1], chenab_values[1][2] - chenab_values[1][0]],
            fmt='o', label='Chenab - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
che_obs = (1.0333, 1.5,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_che, che_obs, marker='s',  color='black', s=400)
# Adding vertical lines between rivers
ax.axvline(x=3.5, color='gray', linestyle='--', linewidth=2)  # Between Indus and Jehlum
ax.axvline(x=7.45, color='gray', linestyle='--', linewidth=2)  # Between Jehlum and Chenab
ax.axvline(x=11.5, color='gray', linestyle='--', linewidth=2)  # Between Chenab and Kabul

#ax.set_xlabel('Years (2023, 2050, 2098)')  # Adjust the x-axis label
#ax.set_ylabel('Probability Ratio', fontsize=40) #, fontweight='bold' , fontname='Times New Roman'
#ax.set_title('Error Bar Plot for River Scenarios')
handles, labels = ax.get_legend_handles_labels()
# Selecting and adjusting the legend entries for RCP 4.5 and RCP 8.5
handles, labels = ax.get_legend_handles_labels()
obs_legend = Line2D([0], [0], marker='s', color='w', markerfacecolor='black', markersize=24)
#ax.legend([obs_legend, handles[0], handles[3]], ['Observed', 'RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 36})
legend = ax.legend([obs_legend, handles[0], handles[3]], ['Observed', 'RCP 4.5', 'RCP 8.5'], loc='lower left', prop={'size': 36})
legend.get_frame().set_linewidth(4)
legend.get_frame().set_edgecolor('black')
#logscale
plt.yscale('log')
years = ['1970s','2010s', '2050s', '2090s'] * 4  # Years repeated for the number of river groups
ax.set_xticks(range(len(years)))  # Setting positions for the ticks
ax.set_xticklabels(years, rotation=90, fontsize=40)  # , weight='bold' Setting custom labels for the primary x-axis

ax.tick_params(axis='x', labelsize=40, width=4, length=18)
ax.tick_params(axis='y', labelsize=40, width=4, length=18)
ax.set_ylim(0.21, 6)
ax.set_xlim(-0.5, 15.6)
ax.tick_params(axis='y', labelsize=36)
#for label in ax.yaxis.get_ticklabels():
    #label.set_fontweight('bold')
plt.tight_layout()

yticks_log = [0.25, 0.5, 1, 2.5, 5]  # Adjust these values based on your desired logarithmic scale
yticklabels = [str(val) for val in yticks_log]  # Convert values to strings for labeling
plt.yticks(yticks_log, yticklabels, fontsize=40)

#boundry thickness
ax = plt.gca()
for spine in ax.spines.values():
    spine.set_linewidth(4)
ax.yaxis.grid(True, linestyle='--', linewidth=1.5) 
# Draw a thick line at y=1
ax.axhline(y=1, color='black', linestyle='-', linewidth=4)
plt.show()


# In[5]:


fig, ax = plt.subplots(figsize=(20, 10)) 
x_offset = 0.3

# Plotting Indus River
ax.errorbar(['indus70', 'indus10', 'indus50', 'indus90'], indus_values[0][0], 
            yerr=[indus_values[0][0] - indus_values[0][1], indus_values[0][2] - indus_values[0][0]],
            fmt='d', label='Indus - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
ind_values = np.arange(len(['indus70', 'indus10', 'indus50', 'indus90']))
shifted_ind = ind_values + x_offset
shift_ind = ind_values -0.3
ax.errorbar(shifted_ind, indus_values[1][0], 
            yerr=[indus_values[1][0] - indus_values[1][1], indus_values[1][2] - indus_values[1][0]],
            fmt='o', label='Indus - RCP 8.5', color='red', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)
ind_obs = (1.5, 1.25,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_ind, ind_obs, marker='s',  color='black', s=400)

# Plotting Kabul River
ax.errorbar(['kabul70', 'kabul10', 'kabul50', 'kabul90'], kabul_values[0][0], 
            yerr=[kabul_values[0][0] - kabul_values[0][1], kabul_values[0][2] - kabul_values[0][0]],
            fmt='d', label='Kabul - RCP 4.5', color='teal', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)
kab_values = np.arange(len(['kabul70', 'kabul10', 'kabul50', 'kabul90']))
shifted_kab = kab_values + 4.2
shift_kab = kab_values + 3.7
ax.errorbar(shifted_kab, kabul_values[1][0], 
            yerr=[kabul_values[1][0] - kabul_values[1][1], kabul_values[1][2] - kabul_values[1][0]],
            fmt='o', label='Kabul - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
kab_obs = (2.5, 1.75,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_kab, kab_obs, marker='s',  color='black', s=400)

# Plotting Jehlum River
ax.errorbar(['jehlum70', 'jehlum10', 'jehlum50', 'jehlum90'], jehlum_values[0][0], 
            yerr=[jehlum_values[0][0] - jehlum_values[0][1], jehlum_values[0][2] - jehlum_values[0][0]],
            fmt='d', label='Jehlum - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

jeh_values = np.arange(len(['jehlum70', 'jehlum10', 'jehlum50', 'jehlum90']))
shifted_jeh = jeh_values + 8.3
shift_jeh = jeh_values + 7.7
ax.errorbar(shifted_jeh, jehlum_values[1][0], 
            yerr=[jehlum_values[1][0] - jehlum_values[1][1], jehlum_values[1][2] - jehlum_values[1][0]],
            fmt='o', label='Jehlum - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
jeh_obs = (0.9, 0.825,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_jeh, jeh_obs, marker='s',  color='black', s=400)
# Plotting Chenab River
ax.errorbar(['chenab70', 'chenab10', 'chenab50', 'chenab90'], chenab_values[0][0], 
            yerr=[chenab_values[0][0] - chenab_values[0][1], chenab_values[0][2] - chenab_values[0][0]],
            fmt='d', label='Chenab - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

che_values = np.arange(len(['chenab70', 'chenab10', 'chenab50', 'chenab90']))
shifted_che = che_values + 12.3
shift_che = che_values + 11.7
ax.errorbar(shifted_che, chenab_values[1][0], 
            yerr=[chenab_values[1][0] - chenab_values[1][1], chenab_values[1][2] - chenab_values[1][0]],
            fmt='o', label='Chenab - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
che_obs = (1.0333, 1.5,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_che, che_obs, marker='s',  color='black', s=400)
# Adding vertical lines between rivers
ax.axvline(x=3.5, color='gray', linestyle='--', linewidth=2)  # Between Indus and Jehlum
ax.axvline(x=7.45, color='gray', linestyle='--', linewidth=2)  # Between Jehlum and Chenab
ax.axvline(x=11.5, color='gray', linestyle='--', linewidth=2)  # Between Chenab and Kabul

#ax.set_xlabel('Years (2023, 2050, 2098)')  # Adjust the x-axis label
#ax.set_ylabel('Probability Ratio', fontsize=40) #, fontweight='bold' , fontname='Times New Roman'
#ax.set_title('Error Bar Plot for River Scenarios')
handles, labels = ax.get_legend_handles_labels()
# Selecting and adjusting the legend entries for RCP 4.5 and RCP 8.5
handles, labels = ax.get_legend_handles_labels()
obs_legend = Line2D([0], [0], marker='s', color='w', markerfacecolor='black', markersize=24)
#ax.legend([obs_legend, handles[0], handles[3]], ['Observed', 'RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 36})
legend = ax.legend([obs_legend, handles[0], handles[3]], ['Observed', 'RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 36},ncol=3)
legend.get_frame().set_linewidth(4)
legend.get_frame().set_edgecolor('black')
#logscale
plt.yscale('log')
years = ['1970s','2010s', '2050s', '2090s'] * 4  # Years repeated for the number of river groups
ax.set_xticks(range(len(years)))  # Setting positions for the ticks
ax.set_xticklabels(years, rotation=90, fontsize=40)  # , weight='bold' Setting custom labels for the primary x-axis

ax.tick_params(axis='x', labelsize=40, width=4, length=18)
ax.tick_params(axis='y', labelsize=40, width=4, length=18)
ax.set_ylim(0.21, 6)
ax.set_xlim(-0.5, 15.6)
ax.tick_params(axis='y', labelsize=36)
#for label in ax.yaxis.get_ticklabels():
    #label.set_fontweight('bold')
plt.tight_layout()

yticks_log = [0.25, 0.5, 1, 2, 4]  # Adjust these values based on your desired logarithmic scale
yticklabels = [str(val) for val in yticks_log]  # Convert values to strings for labeling
plt.yticks(yticks_log, yticklabels, fontsize=40)


#boundry thickness
ax = plt.gca()
for spine in ax.spines.values():
    spine.set_linewidth(4)
ax.yaxis.grid(True, linestyle='--', linewidth=1.5) 
# Draw a thick line at y=1
ax.axhline(y=1, color='black', linestyle='-', linewidth=4)
plt.show()


# In[6]:


fig, ax = plt.subplots(figsize=(20, 10)) 
x_offset = 0.3

# Plotting Indus River
ax.errorbar(['indus70', 'indus10', 'indus50', 'indus90'], indus_values[0][0], 
            yerr=[indus_values[0][0] - indus_values[0][1], indus_values[0][2] - indus_values[0][0]],
            fmt='d', label='Indus - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
ind_values = np.arange(len(['indus70', 'indus10', 'indus50', 'indus90']))
shifted_ind = ind_values + x_offset
shift_ind = ind_values -0.3
ax.errorbar(shifted_ind, indus_values[1][0], 
            yerr=[indus_values[1][0] - indus_values[1][1], indus_values[1][2] - indus_values[1][0]],
            fmt='o', label='Indus - RCP 8.5', color='red', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)
ind_obs = (2, 1.5,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_ind, ind_obs, marker='s',  color='black', s=400)

# Plotting Kabul River
ax.errorbar(['kabul70', 'kabul10', 'kabul50', 'kabul90'], kabul_values[0][0], 
            yerr=[kabul_values[0][0] - kabul_values[0][1], kabul_values[0][2] - kabul_values[0][0]],
            fmt='d', label='Kabul - RCP 4.5', color='teal', alpha=0.8,linewidth=6, markersize=26,elinewidth=6)
kab_values = np.arange(len(['kabul70', 'kabul10', 'kabul50', 'kabul90']))
shifted_kab = kab_values + 4.2
shift_kab = kab_values + 3.7
ax.errorbar(shifted_kab, kabul_values[1][0], 
            yerr=[kabul_values[1][0] - kabul_values[1][1], kabul_values[1][2] - kabul_values[1][0]],
            fmt='o', label='Kabul - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
kab_obs = (2.5, 1.75,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_kab, kab_obs, marker='s',  color='black', s=400)

# Plotting Jehlum River
ax.errorbar(['jehlum70', 'jehlum10', 'jehlum50', 'jehlum90'], jehlum_values[0][0], 
            yerr=[jehlum_values[0][0] - jehlum_values[0][1], jehlum_values[0][2] - jehlum_values[0][0]],
            fmt='d', label='Jehlum - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

jeh_values = np.arange(len(['jehlum70', 'jehlum10', 'jehlum50', 'jehlum90']))
shifted_jeh = jeh_values + 8.3
shift_jeh = jeh_values + 7.7
ax.errorbar(shifted_jeh, jehlum_values[1][0], 
            yerr=[jehlum_values[1][0] - jehlum_values[1][1], jehlum_values[1][2] - jehlum_values[1][0]],
            fmt='o', label='Jehlum - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
jeh_obs = (0.953, 0.835,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_jeh, jeh_obs, marker='s',  color='black', s=400)
# Plotting Chenab River
ax.errorbar(['chenab70', 'chenab10', 'chenab50', 'chenab90'], chenab_values[0][0], 
            yerr=[chenab_values[0][0] - chenab_values[0][1], chenab_values[0][2] - chenab_values[0][0]],
            fmt='d', label='Chenab - RCP 4.5', color='teal', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)

che_values = np.arange(len(['chenab70', 'chenab10', 'chenab50', 'chenab90']))
shifted_che = che_values + 12.3
shift_che = che_values + 11.7
ax.errorbar(shifted_che, chenab_values[1][0], 
            yerr=[chenab_values[1][0] - chenab_values[1][1], chenab_values[1][2] - chenab_values[1][0]],
            fmt='o', label='Chenab - RCP 8.5', color='red', alpha=0.8, linewidth=6, markersize=26,elinewidth=6)
che_obs = (1.0333, 1.5,20,20)  # Modify this line with the actual observational values
ax.scatter(shift_che, che_obs, marker='s',  color='black', s=400)
# Adding vertical lines between rivers
ax.axvline(x=3.5, color='gray', linestyle='--', linewidth=2)  # Between Indus and Jehlum
ax.axvline(x=7.45, color='gray', linestyle='--', linewidth=2)  # Between Jehlum and Chenab
ax.axvline(x=11.5, color='gray', linestyle='--', linewidth=2)  # Between Chenab and Kabul

#ax.set_xlabel('Years (2023, 2050, 2098)')  # Adjust the x-axis label
#ax.set_ylabel('Probability Ratio', fontsize=40) #, fontweight='bold' , fontname='Times New Roman'
#ax.set_title('Error Bar Plot for River Scenarios')
handles, labels = ax.get_legend_handles_labels()
# Selecting and adjusting the legend entries for RCP 4.5 and RCP 8.5
handles, labels = ax.get_legend_handles_labels()
obs_legend = Line2D([0], [0], marker='s', color='w', markerfacecolor='black', markersize=24)
#ax.legend([obs_legend, handles[0], handles[3]], ['Observed', 'RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 36})
legend = ax.legend([obs_legend, handles[0], handles[3]], ['Observed', 'RCP 4.5', 'RCP 8.5'], loc='upper left', prop={'size': 36},ncol=3)
legend.get_frame().set_linewidth(4)
legend.get_frame().set_edgecolor('black')
#logscale
plt.yscale('log')
years = ['1970s','2010s', '2050s', '2090s'] * 4  # Years repeated for the number of river groups
ax.set_xticks(range(len(years)))  # Setting positions for the ticks
ax.set_xticklabels(years, rotation=90, fontsize=40)  # , weight='bold' Setting custom labels for the primary x-axis

ax.tick_params(axis='x', labelsize=40, width=4, length=18)
ax.tick_params(axis='y', labelsize=40, width=4, length=18)
ax.set_ylim(0.4, 6)
ax.set_xlim(-0.5, 15.6)
ax.tick_params(axis='y', labelsize=36)
#for label in ax.yaxis.get_ticklabels():
    #label.set_fontweight('bold')
plt.tight_layout()

yticks_log = [ 0.5, 1, 2, 4]  # Adjust these values based on your desired logarithmic scale
yticklabels = [str(val) for val in yticks_log]  # Convert values to strings for labeling
plt.yticks(yticks_log, yticklabels, fontsize=40)

# Secondary y-axis
#ax2 = ax.twinx()



#boundry thickness
ax = plt.gca()
for spine in ax.spines.values():
    spine.set_linewidth(4)
ax.yaxis.grid(True, linestyle='--', linewidth=1.5) 
# Draw a thick line at y=1
ax.axhline(y=1, color='black', linestyle='-', linewidth=4)
plt.show()


# In[ ]:





# In[ ]:





# In[ ]:





# In[ ]:




